package strategy_pattern.v5;

import java.util.Scanner;

/**
 * v5: 策略模式与简单工厂模式结合
 * @author 米饭好好吃
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double total = 0.0d;
        while (true) {
            System.out.print("请输入商品单价: ");
            String strGoodUnitPrice = sc.next();
            System.out.print("请输入商品数量: ");
            String strGoodCount = sc.next();
            System.out.print("请输入优惠: 0. 正常收费 1. 打八折 2. 打七折 3. 打五折 4. 满300减100: ");
            String choice = sc.next();
            double goodUnitPrice = Double.parseDouble(strGoodUnitPrice);
            double goodCount = Double.parseDouble(strGoodCount);
            CashContext context = new CashContext(choice);
            total += context.getResult(goodUnitPrice * goodCount);
            System.out.println("单价: " + strGoodUnitPrice + " 数量: " + strGoodCount + " 合计: " + total);
            System.out.print("请选择:> 0. 继续 其余. 退出");
            String input = sc.next();
            if (!input.equals("0")) {
                break;
            }
        }
    }
}
